import { Collection, EntitySchema, Ref } from '@mikro-orm/core';
import { OfficeNewsSendRecords } from './OfficeNewsSendRecords';
import { Users } from './Users';

export class OfficeAccounts {
  id!: string;
  name?: string;
  appId?: unknown;
  secret?: unknown;
  token?: unknown;
  aesKey?: unknown;
  iconUrl?: string;
  qrcordeUrl?: string;
  owner?: Ref<Users>;
  type?: string;
  records = new Collection<OfficeNewsSendRecords>(this);
}

export const OfficeAccountsSchema = new EntitySchema({
  class: OfficeAccounts,
  properties: {
    id: { primary: true, type: 'string', columnType: 'bigint' },
    name: { type: 'string', length: 255, nullable: true },
    appId: { type: 'unknown', columnType: 'char(64)', nullable: true },
    secret: { type: 'unknown', columnType: 'char(64)', nullable: true },
    token: { type: 'unknown', columnType: 'char(64)', nullable: true },
    aesKey: { type: 'unknown', columnType: 'char(128)', nullable: true },
    iconUrl: { type: 'string', length: 500, nullable: true },
    qrcordeUrl: { type: 'string', length: 500, nullable: true },
    owner: {
      reference: 'm:1',
      entity: () => Users,
      ref: true,
      nullable: true,
      index: 'owner_id',
    },
    type: { type: 'string', length: 255, nullable: true },
    records: { reference: '1:m', entity: () => OfficeNewsSendRecords, mappedBy: 'office' },
  },
});
